package com.hfut.eeg.common.util;

import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;
import java.util.Random;

/**
 * @author 梁琦
 * @program: eeg
 * @Package com.hfut.eeg.common.util
 * @Description: 生成随机中文名
 * @date 2019-12-10 10:53
 */
@Component
public class RandomUtil {
    static String surName[] = {
            "赵","钱","孙","李","周","吴","郑","王","冯","陈","楮","卫","蒋","沈","韩","杨",
            "朱","秦","尤","许","何","吕","施","张","孔","曹","严","华","金","魏","陶","姜",
            "戚","谢","邹","喻","柏","水","窦","章","云","苏","潘","葛","奚","范","彭","郎",
            "鲁","韦","昌","马","苗","凤","花","方","俞","任","袁","柳","酆","鲍","史","唐"};
    //生成随机中文名
    public static String getRandomJianHan(int len) {
        String randomName = "";
        Random random = new Random();
        for (int i = 0; i < len-1; i++) {
            String str = null;
            int hightPos, lowPos; // 定义高低位
            hightPos = (176 + Math.abs(random.nextInt(39))); // 获取高位值
            lowPos = (161 + Math.abs(random.nextInt(93))); // 获取低位值
            byte[] b = new byte[2];
            b[0] = (new Integer(hightPos).byteValue());
            b[1] = (new Integer(lowPos).byteValue());
            try {
                str = new String(b, "GBK"); // 转成中文
            } catch (UnsupportedEncodingException ex) {
                ex.printStackTrace();
            }
            randomName += str;
        }
        randomName += surName[random.nextInt(surName.length)];
        return randomName;
    }

    //生成随机邮箱


    public static void main(String[] args) {
        for (int i=0;i<10;i++){
            System.out.println(getRandomJianHan(3));
        }
    }

}
